package com.spider.silence.utils;

import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSInputFile;

import java.io.File;
import java.io.IOException;

/**上传文件到GFS
 * Created by qiuhao on 2017/5/2.
 */
public class GridFsUtils {

    public synchronized static void upload2GFS(File file,GridFS gfs){

        try {
            if(file!=null && gfs!=null) {
                GridFSInputFile inputFile = gfs.createFile(file);
                inputFile.save();
                System.out.println("文件"+file.getName()+"上传成功，本地立即进行自动删除。。。。。");
                file.delete();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
